package com.wang.springframework.test.common;

import cn.hutool.core.util.StrUtil;
import com.wang.springframework.beans.BeansException;
import com.wang.springframework.beans.PropertyValue;
import com.wang.springframework.beans.PropertyValues;
import com.wang.springframework.beans.factory.ConfigurableListableBeanFactory;
import com.wang.springframework.beans.factory.config.BeanDefinition;
import com.wang.springframework.beans.factory.config.BeanFactoryPostProcessor;

/**
 * @author wangjianhua
 * @Description
 * @date 2021/8/25/025 17:15
 **/
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {


    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        BeanDefinition beanDefinition = beanFactory.getBeanDefinition("userService");
//        for (PropertyValue propertyValue : beanDefinition.getPropertyValues().getPropertyValues()) {
//            if(propertyValue == null || StrUtil.isEmpty(propertyValue.getName()) ){
//                System.err.println("无属性===========");
//            }
//            System.out.println(propertyValue.getName()+","+propertyValue.getValue());
//        }

        PropertyValues propertyValues = beanDefinition.getPropertyValues();
        propertyValues.addPropertyValue(new PropertyValue("company","通过BeanFactoryPostProcessor增加的测试company"));
    }
}
